    //
//  mainViewController.m
//  yuanhuaPlane
//
//  Created by zhuyuanbin on 6/22/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "mainViewController.h"


@implementation mainViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/
-(id)init
{
	if(self = [super init])
	{
		self.tabBarItem.image = [UIImage imageNamed:@"shop.png"];
		self.tabBarItem.title = @"yuanh";
		self.navigationItem.title = GetStringConfigure(@"shopTitle");
	}
	return self;
}

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView 
{
	UIView *aView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
	aView.backgroundColor = [UIColor clearColor];
	UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainviewbg.png"]];
	[aView addSubview:background];
	[background release];
	self.view = aView;
	[aView release];
	
	UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
	table.dataSource = self;
	table.delegate = self;
	table.backgroundColor = [UIColor clearColor];
	table.userInteractionEnabled = YES;
	table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
	[self.view addSubview:table];
	[table release];
	
	
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}
#pragma mark -
#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
	return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	
	return [[menuItems getMenuItems].ItemsArray count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	
	UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
	UIImageView  *selectedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selectedcell.png"]];
	[cell addSubview:selectedView];
	[selectedView release];
	
}
#pragma mark -
#pragma mark UITableViewData
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
	cell.backgroundColor = [UIColor clearColor];
	Item *item = [[menuItems getMenuItems].ItemsArray objectAtIndex:indexPath.row];
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
	
	
	UIImage*imageCell = [UIImage imageNamed:@"cellbg.png"];
	UIImageView *imageViewCell = [[UIImageView alloc] initWithImage:imageCell];

	[cell addSubview:imageViewCell];
	[imageViewCell release];
	
	UIImage *image = [common  createImage:item.imageSize.width  Height:item.imageSize.height Image:[UIImage imageNamed:item.imageUrl]];
	UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
	//[cell addSubview:imageView];
	[imageView release];
	//--------------------------addLabel----------------------------
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 0.0, 15.0*item.Description.length, 15.0)];
	label.font = [UIFont boldSystemFontOfSize:15];
	label.text = item.Description;
	label.textAlignment = UITextAlignmentLeft;
	label.backgroundColor = [UIColor clearColor];
	
	NSString *address = [item.configureDictionary objectForKey:@"address"];
	UILabel *fightlabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 15.0, 15.0*address.length, 15.0)];
	fightlabel.font = [UIFont boldSystemFontOfSize:15];
	fightlabel.textAlignment = UITextAlignmentLeft;
	fightlabel.text = address;
	fightlabel.backgroundColor = [UIColor clearColor];
	
	UILabel * productNum = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 30.0,15.0*item.productNum.length, 15.0)];
	productNum.font = [UIFont boldSystemFontOfSize:15];
	productNum.textAlignment = UITextAlignmentLeft;
	productNum.text = item.productNum;
	productNum.backgroundColor = [UIColor clearColor];
	
	NSString *price = [item.configureDictionary objectForKey:@"price"]; 
	UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 45.0, 15.0*price.length, 15.0)];
	pricelabel.font = [UIFont boldSystemFontOfSize:15];
	pricelabel.textAlignment = UITextAlignmentLeft;
	pricelabel.text = price;
	pricelabel.textColor = [UIColor colorWithRed:240.0 green:56.0 blue:19.0 alpha:1.0];
	pricelabel.backgroundColor = [UIColor clearColor];
	
	UILabel *salerlabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 60.0, 15.0*item.saler.length, 15.0)];
	salerlabel.font = [UIFont boldSystemFontOfSize:15];
	salerlabel.textAlignment = UITextAlignmentLeft;
	salerlabel.text = item.saler;
	salerlabel.backgroundColor = [UIColor clearColor];
	
	UILabel *telelable = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 75.0, 15.0*item.telephone.length, 15.0)];
	telelable.font = [UIFont boldSystemFontOfSize:15];
	telelable.textAlignment = UITextAlignmentLeft;
	telelable.text = item.telephone;
	telelable.backgroundColor = [UIColor clearColor];
	telelable.textColor = [UIColor greenColor];
	
	
	
	//addview
	/*[cell addSubview:label];
	[cell addSubview:fightlabel];
	[cell addSubview:productNum];
	[cell addSubview:pricelabel];
	[cell addSubview:salerlabel];
	[cell addSubview:telelable];*/
	//release label
	[label release];
	[fightlabel release];
	[productNum release];
	[pricelabel release];
	[salerlabel release];
	[telelable release];
	[cell autorelease];
	return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	Item *itemObject = [[menuItems getMenuItems].ItemsArray objectAtIndex:indexPath.row];
	return itemObject.imageSize.height;
}
@end
